<?php
include ("../../../include/GraphInclude/jpgraph.php");
include ("../../../include/GraphInclude/jpgraph_line.php");
include ("../../../include/GraphInclude/jpgraph_bar.php");

Class LineMaker
{
	// ラインデータ
	var $l1datay;
	// バーデータ
	var $l2datay;
	// X向データタイトル
	var $datax;
	// ラインのレジェンド
	var $lineLegend;
	// バーのレジェンド
	var $barLegend;
	// タイトル
	var $title;
	// X-タイトル
	var $xTitle;
	// Y-タイトル
	var $yTitle;
	
	var $y2Title;
	
	var $y2ScaleMax;
	// 図のXサイズ
	var $xSize;
		
	// 図のYサイズ	
	var $ySize;	
	
function setL1DataY($array)
{
	$this->l1datay = $array;
}

function setL2DataY($array)
{
	$this->l2datay = $array;
}

function setDataX($array)
{
	for($index=0;$index<sizeof($array);$index++)
	{
		if(mb_strlen($array[$index],"utf-8") > 10)
		{
			$array[$index] = mb_substr($array[$index],0,10,"utf-8")."...";
		}	
	}
	$this->datax = $array;
}

function setLineLegend($text)
{
	$this->lineLegend = $text;
}

function setBarLegend($text)
{
	$this->barLegend = $text;
}

function setTitle($text)
{
	$this->title = $text;
}

function setXtitle($text)
{
	$this->xTitle = $text;
}

function setYtitle($text)
{
	$this->yTitle = $text;
}

function setY2title($text)
{
	$this->y2Title = $text;
}

function setY2ScaleMax($maxScalse)
{
	$this->y2ScaleMax = $maxScalse;
}

function setGraphSize($size)
{
	// 標準
	if($size == "0")
	{
		$this->xSize = 800;
		$this->ySize = 300;
	}
	// 最大
	else if($size == "1")
	{
		$this->xSize = 800;
		$this->ySize = 600;		
	}
	else if($size == "2")
	{
		$this->xSize = 300;
		$this->ySize = 200;		
	}
}

function graphMake()
{
// Create the graph. 
//$graph = new Graph(800,600,"auto");	
$graph = new Graph($this->xSize,$this->ySize,"auto");	
$graph->SetScale("textlin");
//$graph->SetYScale("lin");
$graph->SetY2Scale("lin");
//$graph->SetY2Scale("lin",0,$this->y2ScaleMax);
//$graph->SetY2Scale("lin",0,100);
//$graph->SetScale("textlin");

$graph->img->SetMargin(50,50,20,90);	
$graph->SetShadow();
$graph->SetMarginColor(array(233,254,209)); 
$graph->legend->Pos(0.01,0.95,'left','bottom');

// Create the linear error plot
$l1plot=new LinePlot($this->l1datay);
$l1plot->mark->SetType(MARK_FILLEDCIRCLE);
$l1plot->mark->SetFillColor("red");
$l1plot->mark->SetWidth(4);
$l1plot->SetColor("red");
$l1plot->SetWeight(2);
$l1plot->SetLegend($this->lineLegend);

$l1plot->SetBarCenter();


// Create the bar plot
$bplot = new BarPlot($this->l2datay);
$bplot->SetFillGradient("navy","lightsteelblue",GRAD_MIDVER);
$bplot->SetColor("navy");
$bplot->SetLegend($this->barLegend);

// Add the plots to t'he graph
$graph->AddY2($bplot);
$graph->Add($l1plot);
$graph->legend->SetFont(FF_GOTHIC,FS_NORMAL,7);


$graph->title->Set($this->title);
$graph->xaxis->title->Set($this->xTitle);
//$graph->yaxis->title->Set($this->yTitle);
//$graph->y2axis->title->Set($this->y2Title);

$caption=new Text($this->yTitle,0.1,1); 
$caption->SetFont(FF_GOTHIC,FS_NORMAL,7);
$caption->SetColor("red"); 
$graph->AddText($caption);

$graph->title->SetFont(FF_GOTHIC,FS_NORMAL,7);
$graph->yaxis->title->SetFont(FF_GOTHIC,FS_NORMAL);
$graph->y2axis->title->SetFont(FF_GOTHIC,FS_NORMAL,7);
$graph->xaxis->title->SetFont(FF_GOTHIC,FS_NORMAL,7);

$graph->yaxis->SetFont(FF_GOTHIC,FS_NORMAL,7);
$graph->y2axis->SetFont(FF_GOTHIC,FS_NORMAL,7);
$graph->xaxis->SetFont(FF_GOTHIC,FS_NORMAL,7);
$graph->xaxis->SetTickLabels($this->datax);

if(sizeof($this->datax) <= 5)
{
	$graph->xaxis->SetTextTickInterval(1);	
}
else
{
	$graph->xaxis->SetTextTickInterval(floor(sizeof($this->datax)/5) + 1);
}


//$graph->yscale->SetAutoTicks(); 
//$graph->y2scale->SetAutoTicks();

// Display the graph
$graph->Stroke();	
}
}
?>
